package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.Category;
import com.oocl.euc.core.maintenance.model.SubCategory;
import com.oocl.euc.core.requestform.repository.SubCategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class SubCategoryBuilder {
    private SubCategory subCategory;

    @Autowired
    SubCategoryRepository subCategoryRepository;

    public SubCategoryBuilder defaultBuilder() {
        subCategory = new SubCategory();
        subCategory.setSubCategoryID("test subCategoryId");
        subCategory.setCategoryID("test categoryId");
        subCategory.setActive(1);
        subCategory.setCirculationTo("cirInfo");
        subCategory.setSortSeq("1");
        subCategory.setSubcategoryName("subCategory");
        subCategory.setUpdatedAt(new Date());
        return this;
    }

    public SubCategoryBuilder withCategory(Category category) {
        this.subCategory.setCategory(category);
        return this;
    }

    public SubCategory create() {
        return subCategory;
    }

    public SubCategory saveToDB() {
        return this.subCategoryRepository.save(this.subCategory);
    }
}
